package com.junzhiit.nengji.app.web.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.app.service.GoodsImagesService;
import com.junzhiit.nengji.app.web.vo.GoodsImagesAddVO;
import com.junzhiit.nengji.app.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("goods/images")
public class GoodsImagesController extends BaseController {

	@Autowired
	GoodsImagesService goodsImagesService;
	
	@ApiOperation(value = "获取商品相关图片")
	@RequestMapping(value = "/{goodsId}", method = RequestMethod.GET)
	public ResultVO findByGoodsId(@PathVariable String goodsId) {
		return goodsImagesService.findByGoodsId(goodsId);
	}
	
	@ApiOperation(value = "添加商品图片")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(@RequestBody GoodsImagesAddVO[] params) {
		AssertUtil.notNull(params,"goodsImagesAddList is required.");
		List<GoodsImagesAddVO> goodsImagesAddVOs = Arrays.asList(params);
		return goodsImagesService.add(goodsImagesAddVOs);
	}
	
	@ApiOperation(value = "删除商品图片")
	@RequestMapping(method = RequestMethod.DELETE)
	public ResultVO del(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return goodsImagesService.del(id);
	}
}
